﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace Wjtour.BLL
{
    public class resturantpicture_bll : base_dll
    {
        public Wjtour.Domain.resturantpicture Load(int id)
        {
            string sql = "select * from resturantpicture where id=" + id;
            return DbAccess.GetObjects<Wjtour.Domain.resturantpicture>(sql).FirstOrDefault();
        }

        public bool Save(Wjtour.Domain.resturantpicture entity)
        {
            string sql = "";

            DbCommand cmd = DbAccess.CreateCommand();

            if (entity.id > 0)
            {
                sql = @"UPDATE [resturantpicture] SET 
                [resturantid] = @resturantid,
                [pictureid] = @pictureid,
                [addtime] = @addtime
                 WHERE id=@id";
                DbAccess.AddInParameter(cmd, "@id", DbType.Int32, entity.id);

            }
            else
            {
                sql = @"INSERT INTO [resturantpicture]( 
                [resturantid],[pictureid],[addtime])VALUES(
                @resturantid,@pictureid,@addtime)";
            }
            DbAccess.AddInParameter(cmd, "@resturantid", DbType.Int32, entity.resturantid);
            DbAccess.AddInParameter(cmd, "@pictureid", DbType.Int32, entity.pictureid);
            DbAccess.AddInParameter(cmd, "@addtime", DbType.DateTime, entity.addtime);
            cmd.CommandText = sql;
            cmd.CommandType = System.Data.CommandType.Text;
            return DbAccess.ExecuteNonQuery(cmd) > 0;

        }


        public int BatchDelete(string ids)
        {
            string sql = "delete from resturantpicture where id in(" + ids + ")";
            return DbAccess.ExecuteNonQuery(sql);
        }
    }
}
